﻿using Cx.NetCoreUtils.Exceptions;
using Microsoft.AspNetCore.Mvc.Filters;
using Xiao.Code.Entities.Users;
using Xiao.Util;

namespace Xiao.Web.Code
{
    public class AuthorizationAttribute : ActionFilterAttribute
    {
        /// <summary>
        /// 权限拦截
        /// </summary>
        /// <param name="httpContext"></param>
        public override void OnActionExecuting(ActionExecutingContext httpContext)
        {
            string authorization = httpContext.HttpContext.Request.Headers["Authorization"].ToString();
            if (string.IsNullOrEmpty(authorization)) throw new BusinessLogicException(401, "请先登录账号");
            //var path = httpContext.HttpContext.Request.Path.Value;
            var userDto = new RedisUtil().Get<ConsumerDto>(authorization);
            if (userDto == null) throw new BusinessLogicException(401, "请先登录账号");

        }

    }
}
